package cn.btks.resultintegration.achievements.controller;

import cn.btks.commonserver.result.MenuSourceEnum;
import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.commonserver.result.SystemLogEnum;
import cn.btks.commonserver.valid.SystemLog;
import cn.btks.resultintegration.achievements.pojo.LayerFeatures;
import cn.btks.resultintegration.achievements.pojo.TextAchievements;
import cn.btks.resultintegration.achievements.service.LayerFeaturesService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author lijun
 * @Date 2021/2/25 9:17
 */
@Slf4j
@RestController
@RequestMapping("api/v1.0/resultIntegration/achievements/layerFeatures")
@Api(tags = "成果整合模块")
@Validated
public class LayerFeaturesController {

    @Autowired
    LayerFeaturesService layerFeaturesService;

    @GetMapping("/findByName/{name}")
    @ApiOperation("根据文件英文名查询要素管控要求")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "name", value = "文件英文名称", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findByName(@PathVariable("name") String name) {
        LayerFeatures layerFeatures = layerFeaturesService.findByName(name);
        return layerFeatures != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), layerFeatures) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @SystemLog(type = SystemLogEnum.SAVE_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @PostMapping(value = "/save",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "上传图层要素管控要求文件", notes = "解析文件到数据库")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "name", value = "文件英文名称", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "unitClassify", value = "管控单元分类", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "environmentFeatures", value = "环境要素", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "detailFeatures", value = "要素细类", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "spaceRestrain", value = "空间布局约束", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "pollutantRestrain", value = "污染物排放管控", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "environmentRestrain", value = "环境风险防控", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "resourceUtilization", value = "资源利用效率", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "remark", value = "备注", required = true, dataType = "string"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState save(@ApiParam(value = "multipartFile", required = true) MultipartFile multipartFiles, HttpServletRequest request) throws IOException {
        return layerFeaturesService.save(multipartFiles, request);
    }

    @SystemLog(type = SystemLogEnum.UPDATE_LOG,moduleMessage = MenuSourceEnum.MENU_RESULT)
    @PutMapping(value = "/update",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "更新图层要素管控要求文件", notes = "解析文件到数据库")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "name", value = "文件英文名称", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "unitClassify", value = "管控单元分类", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "environmentFeatures", value = "环境要素", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "detailFeatures", value = "要素细类", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "spaceRestrain", value = "空间布局约束", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "pollutantRestrain", value = "污染物排放管控", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "environmentRestrain", value = "环境风险防控", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "resourceUtilization", value = "资源利用效率", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "remark", value = "备注", required = true, dataType = "string"),

            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState update(@ApiParam(value = "multipartFile", required = true) MultipartFile multipartFiles, HttpServletRequest request) throws IOException {
        return layerFeaturesService.update(multipartFiles, request);
    }
}
